package com.five.controller.backstage;

import com.alibaba.fastjson.JSON;
import com.five.dao.backstage.PanDianDao;
import com.five.dao.impl.backstage.PanDianDaoImpl;
import com.five.util.LayTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: jianglin
 * Date: 2020/12/2  9:05
 */
@RestController
@RequestMapping("/pandian")
public class PanDianController {
    @Autowired
    private PanDianDao getPd =new PanDianDaoImpl();
    @RequestMapping("/pdQuery")
    public LayTable pdQuery(){
       List<Map> map= getPd.pdQuery();
        LayTable table = new LayTable(map.size(), map);
        return table;
    }
    @RequestMapping("/pdadd")
    public int pianDianAdd(HttpServletRequest req){
        Map map = (Map) JSON.parse(req.getParameter("data"));
        List<Map> tableDate = (List<Map>) JSON.parse(req.getParameter("panTableData"));
        int a=  getPd.addPianDian(map);

        int b=0;
        int c=0;
        for (Map map1 : tableDate) {
                if (map1.get("faccount")!=null){
                    b +=getPd.addPdXq(map1,a);
                    b +=getPd.addPdXqs(map1);
                }
        }
        return a;
    }
    // 查询盘点表中数据
    @RequestMapping("/pdrId")
    public LayTable querypdrId(Integer page,Integer limit){
        //分页
        int count= getPd.count();
        List<Map> map =  getPd.pdrId(page,limit);
        LayTable table = new LayTable(count,map);
        return table;
    }
    //查询盘点详情表中的数据显示在前台盘点详情中
    @RequestMapping("/pdQueryId")
    public  LayTable pdQueryId(Integer id){
      List<Map> map=  getPd.pdQueryId(id);
        LayTable tab = new LayTable(map.size(), map);
        return tab;
    }
}
